<?php	namespace Home\Controller;
/**
 * 确认订单页
 * @author 武斌   <wubin.mail@foxmail.com>
 */
class OrderLSuccessController extends CommonController
{
	protected $db;
	public function __init()
	{
		$this->db = new \Home\Model\OrderLSuccess;
	}
	/**
	 * 首页
	 */
	public function index()
	{
		$number = Q('get.number',0,'intaval');
		//查询订单表数据
		$data = $this->db->where("number",$number)->first();
		$olData = Db::table('orderlist')->where("orderL_oid",$data['oid'])->get();
		foreach ($olData as $k => $v) {			
			$goods = Db::table('goods')->where("gid",$v['goods_gid'])->first();
			$olData[$k]['goods_gname'] = $goods['gname'];
		}
		View::with('data',$data);
		View::with('olData',$olData);	
		View::make(TEMPLATE . 'orderL_success.html');					
	}
	/**
	 * 添加订单表和订单列表
	 */
	public function add()
	{
		//获得订单号
		$number = Cart::getOrderId();
		if(IS_POST){
			
			if(!$this->db->store($number)){
				$this->error($this->db->error);
			}
		}
		//清除session中已提交订单的商品
		foreach ($_SESSION['ORDERL']['ord'] as $k => $v) {			
			$_SESSION['cart']['total_rows']=$_SESSION['cart']['total_rows'] - ($v['num']);//删除之后把总条数修改掉
			$_SESSION['cart']['total'] = $_SESSION['cart']['total'] - ($v['total']);
			unset($_SESSION['cart']['goods'][$k]);
		}
		//购物车中商品全部都提交订单，则将cart删掉
		if(count($_SESSION['cart']['goods'])==0){
			unset($_SESSION['cart']);
		}
		//订单提交成功后把之前存入session的ORDERL清除掉,自己设置的数组
		unset($_SESSION['ORDERL']);
		go(U('index',array('number'=>$number)));//添加完成之后跳转到订单成功页面					
	}
}
